package jspservlet.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jspservlet.dao.FamilyDAO;
import jspservlet.dao.impl.FamilyDAOImpl;
import jspservlet.vo.Family;
public class RegisFamilyServlet extends HttpServlet{
	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
	}
	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		Family family = new Family();
		family.setFamilyID(req.getParameter("fID"));
		family.setfName(req.getParameter("fName"));
		family.setAddress(req.getParameter("address"));
		family.setShanchu(0);
		FamilyDAO dao = new FamilyDAOImpl();
		int flag = 0;
		try {
			flag = dao.registfamily(family);
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
		if(flag == 1){
			res.getWriter().println("<script>alert('Registration Successful!')</script>");
			res.getWriter().println("<script>window.location.href='./index.jsp'</script>");
		}
		else{
			res.getWriter().println("<script>alert('Registration Failed!')</script>");
			res.getWriter().println("<script>window.location.href='./RegisterFamily.jsp'</script>");
		}
	}
}
